package com.example.qiao.mvp.view;


import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.mylibrary.mvp.view.BaseFragment;
import com.example.qiao.R;
import com.example.qiao.adapter.GuanAdapter;
import com.example.qiao.adapter.TongAdapter;
import com.example.qiao.adapter.ZhongAdapter;
import com.example.qiao.bean.GUAN;
import com.example.qiao.bean.Tong;
import com.example.qiao.bean.Zhong;
import com.example.qiao.mvp.contract.PostContract;
import com.example.qiao.mvp.model.PostModel;
import com.example.qiao.mvp.presenter.PostPresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.json.JSONException;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListFragment extends BaseFragment<PostPresenter> implements PostContract.View {
    int type;
    private SmartRefreshLayout sm;
    private RecyclerView rv;

    public ListFragment(int type) {
        this.type = type;
    }


    @Override
    public int bongLayout() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView() {
        sm = (SmartRefreshLayout) findViewById(R.id.sm);
        rv = (RecyclerView) findViewById(R.id.rv);
        rv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
    }

    @Override
    public void initData() {
        mPresenter = new PostPresenter(new PostModel(), this);
        switch (type) {
            case 0:
                try {
                    mPresenter.initGuan();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            case 1:
                mPresenter.initZhong();
                break;
            case 2:
                mPresenter.initTong();
                break;
        }
    }

    @Override
    public void initGuan(List<GUAN> list) {
        GuanAdapter guanAdapter = new GuanAdapter(R.layout.item, list);
        rv.setAdapter(guanAdapter);
    }

    @Override
    public void initZHong(List<Zhong> list) {
        ZhongAdapter zhongAdapter = new ZhongAdapter(R.layout.item, list);
        rv.setAdapter(zhongAdapter);
    }

    @Override
    public void initTong(List<Tong> list) {
        TongAdapter tongAdapter = new TongAdapter(R.layout.item, list);
        rv.setAdapter(tongAdapter);
    }

    @Override
    public void Toast(String message) {

    }
}
